/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using DaveSexton.DocProject.Engine;

namespace DaveSexton.DocProject.Sandcastle
{
	internal sealed class MergeTocBuildStep : BuildStep<SandcastleBuildEngine>
	{
		#region Public Properties
		public override string Name
		{
			get
			{
				return Resources.Text.MergeTocBuildStepName;
			}
		}
		#endregion

		#region Private / Protected
		private readonly string topicsFile, mergeWithTocFile, outputTocFile;
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="MergeTocBuildStep" /> class.
		/// </summary>
		public MergeTocBuildStep(SandcastleBuildEngine engine, string topicsFile, string mergeWithTocFile, string outputTocFile)
			: base(engine)
		{
			this.topicsFile = topicsFile;
			this.mergeWithTocFile = mergeWithTocFile;
			this.outputTocFile = outputTocFile;
		}

		/// <summary>
		/// Constructs a new instance of the <see cref="MergeTocBuildStep" /> class.
		/// </summary>
		public MergeTocBuildStep(SandcastleBuildEngine engine, string topicsFile, string outputTocFile)
			: base(engine)
		{
			this.topicsFile = topicsFile;
			this.outputTocFile = outputTocFile;
		}
		#endregion

		#region Methods
		protected override void ExecuteInternal(BuildContext context)
		{
			context.TraceLine();
			context.TraceLine("Creating merged TOC file: {0}", outputTocFile);

			int conceptualTopicCount = (string.IsNullOrEmpty(mergeWithTocFile))
				? TopicManagement.ConceptualTopicFileManager.CreateToc(topicsFile, outputTocFile)
				: TopicManagement.ConceptualTopicFileManager.CreateMergedToc(topicsFile, mergeWithTocFile, outputTocFile);

			context.TraceLine(Resources.Text.Done);
			context.TraceLine();
			context.TraceLine("Included {0} conceptual topic(s).", conceptualTopicCount);
		}

		protected override void CancelInternal(BuildContext context)
		{
			// do nothing
		}
		#endregion
	}
}
